<%@page import="java.util.StringTokenizer"%>
<%@page import="com.liferay.portal.service.ListTypeServiceUtil"%>
<%@page import="com.liferay.portal.model.ListType"%>
<%@ include file="/init.jsp"%>

<%
ListType mappedFee = (ListType) request.getAttribute("mappedFee");
System.out.println("doing ID >>>" + mappedFee.getListTypeId());

List<ListType> mappedSubFees = 
	ListTypeServiceUtil.getListTypes
		("com.teqbridgeltd.liferay.model.map.Fees.Application Fees for C of O Recertification" );
System.out.println("com.teqbridgeltd.liferay.model.map.Fees." + mappedFee.getName() +"<<<");

%>
		
		<aui:layout>
	  	<aui:column columnWidth="100">
	  		<!--  this is the fees description -->
	  		<div id="selected_<%=mappedFee.getListTypeId() %>"></div>
	  	</aui:column>
	  </aui:layout>
	  
	  <aui:layout>
			<aui:column>
				<span class="hder" id="feesName_<%=mappedFee.getListTypeId() %>" ><%=mappedFee.getName() %></span>
			</aui:column>
		</aui:layout>
	  
	  <aui:layout>
	  	<aui:column columnWidth="33">
	  		&nbsp;
	  	</aui:column>
	  	<aui:column columnWidth="33">
	  		
	  		<!-- this is if there is drop down -->		
				<%
				if(mappedSubFees.size() >= 2){
				%>
				
				<select onChange="pickFee(this, <%=mappedFee.getListTypeId() %>);" id="purpose_<%=mappedFee.getListTypeId() %>" 
				name="purpose_<%=mappedFee.getListTypeId() %>" >
					<option value="">-Select purpose-</option>
					<%
					for(int h=0; h<mappedSubFees.size(); h++){
						ListType mappedSubFee = mappedSubFees.get(h);
						String name = mappedSubFee.getName();
						StringTokenizer strTok = new StringTokenizer(name, "~");
						String firstPart, secondPart, fees;
						firstPart= secondPart= fees ="";
						try{
							 firstPart = strTok.nextToken().replaceAll(mappedFee.getName(), "");
							 secondPart = strTok.nextToken();
							 fees = strTok.nextToken();
						}catch(Exception ex){
							
						}
					%>
					<option value="<%= fees %>"><%=firstPart  %></option>
	        <%
					}
	        %>
				</select>
				
				<%
				}
				%>
	  	</aui:column>
	  	<aui:column columnWidth="33">
					
			
	  		<!-- This for displaying of the result -->
				<%
				if(mappedSubFees.size() >= 2){
				%>
				<input class="resultbox" readonly="readonly" readonly="readonly" 
				id="result_<%=mappedFee.getListTypeId() %>" name="result_<%=mappedFee.getListTypeId() %>" type="text">
				<%
				}else if(mappedSubFees.size() == 1) {
					
					ListType mappedSubFee = mappedSubFees.get(0);
					StringTokenizer strTok = new StringTokenizer(mappedSubFee.getName(), "~");
					String firstPart, secondPart, fees;
					firstPart= secondPart= fees ="";
					try{
						 firstPart = strTok.nextToken(); //.replaceAll(mappedFee.getName(), "");
						 secondPart = strTok.nextToken();
						 fees = strTok.nextToken();
					}catch(Exception ex){
						
					}
				%>
				<input class="resultbox" readonly="readonly" name="result_<%=mappedFee.getListTypeId() %>"  id="result_<%=mappedFee.getListTypeId() %>" type="text" value="<%=fees %>">
				<%}
				%>
	  	</aui:column>
	  </aui:layout>
			
<script>
function ComputeFee_<%=mappedFee.getListTypeId() %>(){
	var result = document.getElementById('result_<%=mappedFee.getListTypeId() %>');
	var salesAmount = document.getElementById('<portlet:namespace/>saleAmount');
	var cgtTax =  document.getElementById('cgtTax');
	//alert(salesAmount.value);
	result.value = parseFloat(salesAmount.value * cgtTax.value).toFixed(2);
	hidePrintButton();
	computeTotal();
}
</script> 